package com.gitee.neuray.security.mail.rest;

import com.gitee.neuray.security.common.msg.ObjectRestResponse;
import com.gitee.neuray.security.common.rest.BaseController;
import com.gitee.neuray.security.mail.biz.MailBiz;
import com.gitee.neuray.security.mail.entity.SysMailSource;
import com.gitee.neuray.security.mail.vo.SendStausVo;
import com.gitee.neuray.security.mail.vo.SysMailSourceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @auther: zhuqz
 * @date: 2020/2/26 09:48
 * @description:
 */
@RestController
@RequestMapping("mail")
public class MailController extends BaseController<MailBiz, SysMailSource> {
    @Autowired
    protected HttpServletRequest request;
    @Autowired
    protected MailBiz mailBiz;
    @PostMapping("add")
    public ObjectRestResponse add(@RequestBody SysMailSourceVo vo){
        //EntityUtils.setCreatAndUpdatInfo(vo);

        try {
            this.mailBiz.add(vo);
        } catch (Exception e) {
            e.printStackTrace();
            return  new ObjectRestResponse().rel(true).msg("500").data("添加失败");
        }
        return  new ObjectRestResponse().rel(true).msg("200").data("添加成功");
    }
    @GetMapping("queryById")
    public ObjectRestResponse queryById(@RequestParam("id") String id) throws Exception{
        SysMailSourceVo vo = this.mailBiz.queryById(id);
        return  new ObjectRestResponse().rel(true).msg("200").data(vo);
    }
    //发送邮件
    @GetMapping("sendTimerMail")
    public ObjectRestResponse sendTimerMail() throws Exception{
        SendStausVo vo = this.mailBiz.sendTimerMail();
        return  new ObjectRestResponse().rel(true).msg("200").data(vo);
    }
    //发送生日邮件
    @GetMapping("sendBirthDayTimerMail")
    public ObjectRestResponse sendBirthDayTimerMail() throws Exception{
        SendStausVo vo = this.mailBiz.sendBirthdayTimerMail();
        return  new ObjectRestResponse().rel(true).msg("200").data(vo);
    }

}